package com.yhx.security.guangfa;


import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TreeSet;

public class WriteFile {

    public static void fileWriter(String fileName,List<String> clist) throws IOException{        //����һ��FileWriter����
        FileWriter fw = new FileWriter(fileName);        //����clist����д�뵽fileName��
        for (String str: clist){
            fw.write(str);
            fw.write("\n");
        }        //ˢ�»�����
        fw.flush();        //�ر��ļ�������
        fw.close();
    }

    public static TreeSet<String> readFileByLines(String fileName) throws IOException{
        File file = new File(fileName);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String tempString = null;        //����һ������
        TreeSet<String> nums = new TreeSet<String>();        //���ж�ȡ�ļ����ݣ�����ŵ�����
        while ((tempString = reader.readLine()) != null){
            System.out.println("tempString="+tempString);
            nums.add(tempString);
        }
        reader.close();        //���ؼ��ϱ���
        return nums;
    }

    public static void main(String[] args) throws IOException{        //����writeFile����wf
        //writeFile wf = new writeFile();        //��ȡ�ļ����ݱ��浽һ�����϶�����
        //TreeSet<String> ts = wf.readFileByLines("F:/A_remain.txt");        //�����϶���ts�����ݱ��浽text.txt�ļ���
        //TreeSet<String> t=new TreeSet<String>();
        List<String> t=new ArrayList<String>();
        char c=(char) 27;
        String abc="zhangsan";
        StringBuilder sb=new StringBuilder(abc);
        String bcd="lisiwangermazi";
        String lisi="lise";
        sb.append(c).append(bcd).append(c).append(lisi);
        System.out.println(sb.toString());
        String str=sb.toString();
        t.add("328");
        t.add(str+"333");
        t.add(str+"444");
        t.add(str+"111");
        WriteFile.fileWriter("D:\\Coding\\threadStudy\\src\\main\\webapp\\"+formatDateTimeyyyyMM(new Date())+"\\"+"filel33.txt", t);

        String dataStr=formatTime(new Date());
        String tradeDate=dataStr.substring(0,8);
        String tradeTime=dataStr.substring(8,14);

        System.out.println("tradeDate="+tradeDate+" ,tradeTime="+tradeTime);
    }

    public static String formatDateTimeyyyyMM(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        return dateFormat.format(date);
    }

    public static String formatTime(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        return dateFormat.format(date);
    }
}
